package cn.source.web.controller.gygl;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.system.domain.Schedule;
import cn.source.system.service.IScheduleService;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
/**
 * 课表管理Controller
 *
 * @author gygl
 * @date 2023-09-06
 */
@RestController
@RequestMapping("/system/schedule")
public class ScheduleController extends BaseController
{
    @Autowired
    private IScheduleService scheduleService;
    /**
     * 查询课表管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:schedule:list')")
    @GetMapping("/list")
    public TableDataInfo list(Schedule schedule)
    {
        startPage();
        List<Schedule> list = scheduleService.selectScheduleList(schedule);
        return getDataTable(list);
    }
    /**
     * 导出课表管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:schedule:export')")
    @Log(title = "课表管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Schedule schedule)
    {
        List<Schedule> list = scheduleService.selectScheduleList(schedule);
        ExcelUtil<Schedule> util = new ExcelUtil<Schedule>(Schedule.class);
        util.exportExcel(response, list, "课表管理数据");
    }
    /**
     * 获取课表管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:schedule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(scheduleService.selectScheduleById(id));
    }
    /**
     * 新增课表管理
     */
    @PreAuthorize("@ss.hasPermi('system:schedule:add')")
    @Log(title = "课表管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Schedule schedule)
    {
        return toAjax(scheduleService.insertSchedule(schedule));
    }
    /**
     * 修改课表管理
     */
    @PreAuthorize("@ss.hasPermi('system:schedule:edit')")
    @Log(title = "课表管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Schedule schedule)
    {
        return toAjax(scheduleService.updateSchedule(schedule));
    }
    /**
     * 删除课表管理
     */
    @PreAuthorize("@ss.hasPermi('system:schedule:remove')")
    @Log(title = "课表管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scheduleService.deleteScheduleByIds(ids));
    }
    /**
     * 将Excel表导入数据库
     * @param file
     * @return
     */
    @ApiOperation("将Excel导入数据库")
    @PostMapping("/imports")
    public AjaxResult importExcel( MultipartFile file) throws IOException {
       scheduleService.importExcel(file);
        return AjaxResult.success();
    }
    /**
     * 判断当天是否有课
     */
    @ApiOperation("判断当天是否有课")
    @GetMapping("/judgeClass")
    public AjaxResult judgeClass(){
        return AjaxResult.success(scheduleService.judgeClass());
    }
}
